
local imgui = require "cimgui" -- cimgui is the folder containing the Lua module (the "src" folder in the git repository)


--------------------------------------------------------------------------------------------

app = {}

app.draw = function()
    local p = love.filesystem.getWorkingDirectory()
    love.graphics.print("work_dir = "..p)

    love.graphics.setColor(1, 0.2, 0.5)
    love.graphics.circle("fill", 100,100,50,100)

    love.graphics.setColor(1, 1, 1)
    local img = love.graphics.newImage('asserts/gou.jpg')
    love.graphics.draw(img, 400, 100)
end

app.show_window = function()
    if imgui.Begin("test") then
     
        if imgui.Button("push me") then
            app.show_tip = not app.show_tip
        end

        if app.show_tip then
            imgui.Text("hi~ I am here ~ ~")
        end

        if imgui.Button("samples") then
            app.show_samples = not app.show_samples
        end
    end
    imgui.End()
end

--------------------------------------------------------------------------------------------


love.load = function()
    imgui.love.Init() -- or imgui.love.Init("RGBA32") or imgui.love.Init("Alpha8")
end

love.draw = function()

    app.draw()

    app.show_window()

    -- example window
    if app.show_samples then
        imgui.ShowDemoWindow()
    end
    
    -- code to render imgui
    imgui.Render()
    imgui.love.RenderDrawLists()
end

love.update = function(dt)
    imgui.love.Update(dt)
    imgui.NewFrame()
end

love.mousemoved = function(x, y, ...)
    imgui.love.MouseMoved(x, y)
    if not imgui.love.GetWantCaptureMouse() then
        -- your code here
    end
end

love.mousepressed = function(x, y, button, ...)
    imgui.love.MousePressed(button)
    if not imgui.love.GetWantCaptureMouse() then
        -- your code here 
    end
end

love.mousereleased = function(x, y, button, ...)
    imgui.love.MouseReleased(button)
    if not imgui.love.GetWantCaptureMouse() then
        -- your code here 
    end
end

love.wheelmoved = function(x, y)
    imgui.love.WheelMoved(x, y)
    if not imgui.love.GetWantCaptureMouse() then
        -- your code here 
    end
end

love.keypressed = function(key, ...)
    imgui.love.KeyPressed(key)
    if not imgui.love.GetWantCaptureKeyboard() then
        -- your code here 
    end
end

love.keyreleased = function(key, ...)
    imgui.love.KeyReleased(key)
    if not imgui.love.GetWantCaptureKeyboard() then
        -- your code here 
    end
end

love.textinput = function(t)
    imgui.love.TextInput(t)
    if imgui.love.GetWantCaptureKeyboard() then
        -- your code here 
    end
end

love.quit = function()
    return imgui.love.Shutdown()
end

-- for gamepad support also add the following:

love.joystickadded = function(joystick)
    imgui.love.JoystickAdded(joystick)
    -- your code here 
end

love.joystickremoved = function(joystick)
    imgui.love.JoystickRemoved()
    -- your code here 
end

love.gamepadpressed = function(joystick, button)
    imgui.love.GamepadPressed(button)
    -- your code here 
end

love.gamepadreleased = function(joystick, button)
    imgui.love.GamepadReleased(button)
    -- your code here 
end

-- choose threshold for considering analog controllers active, defaults to 0 if unspecified
local threshold = 0.2 

love.gamepadaxis = function(joystick, axis, value)
    imgui.love.GamepadAxis(axis, value, threshold)
    -- your code here 
end
